package initialize

import (
	"coolcar/global"
	"coolcar/utils/token"
	"io/ioutil"
	"log"
	"os"
	"time"

	"github.com/dgrijalva/jwt-go"
)

func InitJWT() {
	pkFile, err := os.Open(".privateKey")
	if err != nil {
		log.Fatal("can not open private key file", err)
	}

	b, err := ioutil.ReadAll(pkFile)
	if err != nil {
		log.Fatal("ioutil.ReadAll failed", err)
	}

	privateKey, err := jwt.ParseRSAPrivateKeyFromPEM(b)
	if err != nil {
		log.Fatal("jwt.ParseRSAPrivateKeyFromPEM failed", err)
	}
	global.JWTTokenGen = token.NewJWTTokenGen("coolcar/auth", time.Second*60, privateKey)
}
